package com.test.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.test.common.R;
import com.test.entity.SysMenu;
import com.test.service.SysMenuService;


@RestController
@RequestMapping("/sys/menu")
public class SysMenuController extends AbstractController {

	@Resource
	private SysMenuService sysMenuService;

	/**
	 * 用户菜单
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/user")
	public R user() {
		R r = sysMenuService.listUserMenu(getUserId());
		return r;
	}

	@RequestMapping("/list")
	public List<SysMenu> listMenu(@RequestParam Map<String, Object> params) {

		return sysMenuService.listMenu(params);
	}

	/**
	 * 选择菜单(添加、修改)
	 * 
	 * @return
	 */
	@RequestMapping("/select")
	public R select() {
		return sysMenuService.listNotButton();
	}

	/**
	 * 查询详情
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/info")
	public R info(@RequestBody Long id) {
		return sysMenuService.getMenuById(id);
	}

	/**
	 * 新增菜单
	 * 
	 * @param menu
	 * @return
	 */
	@RequestMapping("/save")
	public R save(@RequestBody SysMenu menu) {
		return sysMenuService.saveMenu(menu);
	}

	/**
	 * 修改菜单
	 * 
	 * @param menu
	 * @return
	 */
	@RequestMapping("/update")
	public R update(@RequestBody SysMenu menu) {
		return sysMenuService.updateMenu(menu);
	}

	/**
	 * 删除菜单
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/remove")
	public R remove(@RequestBody Long[] id) {
		return sysMenuService.batchRemove(id);
	}

	/*
	 * @RequestMapping("/list") public JSONObject listMenu(@RequestParam Map<String,
	 * Object> params) {
	 * 
	 * String sEcho = null; int iDisplayStart = 0; int iDisplayLength = 0; if (null
	 * != params.get("sEcho")) { sEcho = params.get("sEcho").toString(); } if (null
	 * != params.get("iDisplayStart")) { iDisplayStart =
	 * Integer.valueOf(params.get("iDisplayStart").toString()); } if (null !=
	 * params.get("iDisplayLength")) { iDisplayLength =
	 * Integer.valueOf(params.get("iDisplayLength").toString()); } List<SysMenu>
	 * list = sysMenuService.listMenu(params);
	 * 
	 * JSONObject resultJson = new JSONObject(); resultJson.put("aaData", list);
	 * resultJson.put("sEcho", sEcho); resultJson.put("iTotalRecords", list.size());
	 * resultJson.put("iTotalDisplayRecords", list.size()); resultJson.put("Error",
	 * ""); return resultJson; }
	 */
}
